﻿using System.Globalization;
using System.Windows;
using System.Windows.Input;
using CapstoneProjectAEReader.Common.Utility;

namespace CapstoneProjectAEReader.GUIs.TranslationGUI
{
    /// <summary>
    /// Interaction logic for BookmarkHeader.xaml
    /// </summary>
    public partial class BookmarkHeader
    {
        public string StrHeader;
        public string StrPageNumber;
        private const string NotBLank = "bookmarkNotBlank";
        private const string InvalidPageNo = "invalidPageNo";
        public string strTotalPageNumber;

        public BookmarkHeader()
        {
            InitializeComponent();
        }

        public BookmarkHeader(string strTotalPage, bool isUpdate)
        {
            strTotalPageNumber = strTotalPage;

            InitializeComponent();
            if (isUpdate)
            {
                txtPageNo.Visibility = Visibility.Hidden;
            }
            txtPageNo.Text = "0";
        }

        public BookmarkHeader(string strTotalPage, bool isUpdate, string description)
        {
            strTotalPageNumber = strTotalPage;

            InitializeComponent();
            if (isUpdate)
            {
                txtPageNo.Visibility = Visibility.Hidden;
            }
            tbHeader.Text = description;
            txtPageNo.Text = "0";
        }

        public BookmarkHeader(string strTotalPage, bool isUpdate, string description, int page)
        {
            strTotalPageNumber = strTotalPage;

            InitializeComponent();
            if (isUpdate)
            {
                txtPageNo.Visibility = Visibility.Hidden;
            }
            tbHeader.Text = description;
            txtPageNo.Text = page.ToString(CultureInfo.InvariantCulture);
        }

        private void CloseCommandHandler(object sender, ExecutedRoutedEventArgs e)
        {
            Close();
        }

        private void BtOkClick(object sender, RoutedEventArgs e)
        {
            string strHeader = tbHeader.Text;
            int intPageNumber;
            if (!string.IsNullOrWhiteSpace(strHeader))
            {
                try
                {
                    intPageNumber = int.Parse(txtPageNo.Text);
                    if (intPageNumber < 0 || intPageNumber > int.Parse(strTotalPageNumber))
                    {
                        Utilities.ShowWarningMesbox(ResourceReader.GetResourceContent(InvalidPageNo));
                    }
                    else
                    {
                        StrHeader = tbHeader.Text;
                        StrPageNumber = txtPageNo.Text;
                        this.DialogResult = true;
                        Close();
                    }

                }
                catch (System.Exception)
                {
                    Utilities.ShowWarningMesbox(ResourceReader.GetResourceContent(InvalidPageNo));
                }

            }
            else
            {
                Utilities.ShowWarningMesbox(ResourceReader.GetResourceContent(NotBLank));
            }

        }
    }
}
